package com.yjr.server.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author yjr
 * @version 1.0.0
 * @ClassName AuthenticationFilter.java
 * @Description TODO
 * @createTime 2021年12月02日 17:42:00
 */
@WebFilter(filterName = "AuthenticationFilter")
public class AuthenticationFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;

        HttpServletResponse res = (HttpServletResponse) response;

        HttpSession session = req.getSession();

        if ((Boolean) session.getAttribute("isLogin")) {
            filterChain.doFilter(request, response);
            return;

        }

        //跳转至sso认证中心

        res.sendRedirect("sso-server-url-with-system-url");
    }

    @Override
    public void destroy() {

    }
}
